<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <soncpn ref="son1"></soncpn>
        <soncpn ref="son2"></soncpn>
        <hr>
        <button @click="showChildren">显示子组件</button>
    </div>
</body>

<template id="soncpn">
    <div>
        <h1>我是子组件</h1>
        <button @click="showParent">显示爸爸</button>
    </div>
</template>
<script src="../js/http_cdn.bootcdn.net_ajax_libs_vue_2.6.6_vue.js"></script>
<script>
    new Vue({
        el: "#app",
        data: {

        },
        methods: {
            showChildren(){
                // console.log(this.$children)
                // this.$children[0].showMsg("爸爸给儿子传参")

                this.$refs.son1.showMsg("爸爸给儿子传参")
                console.log(this.$refs.son1.name)
                console.log(this.$refs)
            }
        },
        components: {
            soncpn: {
                template: "#soncpn",
                data() {
                    return {
                        name:"我是儿子name"
                    }
                },
                methods: {
                    showMsg(args) {
                        console.log(args)
                    },
                    showParent(){
                        console.log(this.$parent)
                    }
                },
            }
        }
    })
</script>

</html>
